/**
 * @file ZSTEdgeAndNode.h
 * @brief the node and edge structures for suffix tree
 * @author babear.wangz
 * @date 2011-04-13
 */

#ifndef ZSTEdgeAndNode_H
#define ZSTEdgeAndNode_H

#include "ZTraits.h"

/**
 * @class ZSTEdge
 * @brief suffix tree edge structure
 * @author babear.wangz
 * @date 2011-04-07
 */
template <typename NodeIdType>
struct ZSTEdge {
    // the emitting node
    NodeIdType node;
    // the ending node
    NodeIdType enode;
    // the starting index in sequence buffer
    uint32_t start;
    // the ending index in sequence buffer
    uint32_t end;
    // the next edge which has the same emitting node
    uint32_t next;
    // constructor
    ZSTEdge()
    : node(NodeIDHash<NodeIdType>::Empty())
    , enode(NodeIDHash<NodeIdType>::Empty())
    {
    }
    inline bool IsEmpty()
    {
        return node == NodeIDHash<NodeIdType>::Empty();
    }
};

/**
 * @class ZSTNode
 * @brief the suffix tree's node structure. includes a suffix link and it's
 * @brief   first edge to it's first child
 * @author babear.wangz
 * @date 2011-04-13
 */
template <typename NodeIdType>
struct ZSTNode {
    NodeIdType suflink;//suffix link
    uint32_t first_edge;// first edge starting from this node
    // the default constructor
    ZSTNode()
    : suflink(NodeIDHash<NodeIdType>::Empty())
    , first_edge(-1)
    {
    }
    // the copy constructor
    ZSTNode(const ZSTNode& n)
    : suflink(n.suflink)
    , first_edge(n.first_edge)
    {
    }
};

// class ZTypeTraits's template specialization for ZSTNode,
// the detail is in ZTraits.h
template <typename T> struct ZTypeTraits<ZSTNode<T> > {
    static bool equal(const ZSTNode<T>& a, const ZSTNode<T>& b)
    {
        return (&a) == (&b);
    }
    static const bool need_construct = true;
    static const ZSTNode<T> empty;
};

#endif


